﻿@model Xuanren_FrontEnd.Model.Admin
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="~/Content/lib/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/lib/layui/layui.js"></script>
</head>
<body>
    <form class="layui-form" action="">
        <input type="hidden" value="@Model.id" id="id" />
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" value="@Model.username" id="username" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-block">
                <input type="text" id="oldPassword" required lay-verify="required" placeholder="请输入原密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="text" id="newPassword" required lay-verify="required" placeholder="请输入新密码密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        //Demo
        layui.use(['form', 'upload'], function () {
            var form = layui.form;
            var upload = layui.upload;
            var $ = layui.$;
            //监听提交
            form.on('submit(formDemo)', function (data) {
                $.ajax({
                    url: "/Back/Admin/DealPwd",
                    type: "post",
                    data: {
                        id: $("#id").val(),
                        username: $("#username").val(),
                        oldPassword: $("#oldPassword").val(),
                        newPassword: $("#newPassword").val()
                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 0) {
                            layer.alert(res.msg, function (index) {
                                //do something
                                layer.close(index); //如果设定了yes回调，需进行手工关闭
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                $.post('/Back/Admin/SignOut', function () {
                                    console.log("退出");
                                })
                            });


                        } else {
                            layer.alert(res.msg);
                        }
                    }
                })
                return false;
            });
        });
    </script>
</body>
</html>
